﻿using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp.AutoMapper;
using Volo.Abp.ObjectMapping;
using Xms.Abp.AutoMapper;
using Xms.Abp.ObjectMapping;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class XmsAbpAutoMapperServiceCollectionExtensions
    {
        public static IServiceCollection AddXmsAutoMapperObjectMapper(this IServiceCollection services)
        {
            return services
                .AddTransient<IXmsAutoObjectMappingProvider, AutoMapperXmsAutoObjectMappingProvider>()
                .Replace(ServiceDescriptor.Transient<IAutoObjectMappingProvider>(s => s.GetRequiredService<IXmsAutoObjectMappingProvider>()))
                .Replace(ServiceDescriptor.Transient(s => s.GetRequiredService<IXmsAutoObjectMappingProvider>() as AutoMapperAutoObjectMappingProvider));
        }

        public static IServiceCollection AddXmsAutoMapperObjectMapper<TContext>(this IServiceCollection services)
        {
            return services
                .AddTransient<IXmsAutoObjectMappingProvider<TContext>, AutoMapperXmsAutoObjectMappingProvider<TContext>>()
                .Replace(ServiceDescriptor.Transient<IAutoObjectMappingProvider<TContext>>(s => s.GetRequiredService<IXmsAutoObjectMappingProvider<TContext>>()))
                .Replace(ServiceDescriptor.Transient(s => s.GetRequiredService<IXmsAutoObjectMappingProvider<TContext>>() as AutoMapperAutoObjectMappingProvider<TContext>));
        }
    }
}
